#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>

#include "Student.h"
#include "StudentRegister.h"

#include "LanguageCourse.h"
#include "Mathematics.h"
#include "English.h"
#include "Swedish.h"
#include "CourseException.h"

using namespace std;

void main3_1()
{
	cout << "main3_1" << endl;
	Student s1("Kalle", "Anka", 1991);
	Student s2;
	s2.setFirstName("Anders");
	s2.setSecondName("And");
	s2.setEnrollmentYear(1992);
	cout << s2.getSecondName() << "," << s2.getFirstName() << ": " << s2.getEnrollmentYear() << endl;
}

void main3_2()
{
	cout << "main3_2" << endl;
	Student s1;
	s1.write();
	s1.read();
	s1.write();
}

void main3_3()
{
	cout << "main3_3" << endl;
	Student s1("Kalle", "Anka", 1991);
	Student s2;
	s2.setFirstName("Anders");
	s2.setSecondName("And");
	s2.setEnrollmentYear(1992);
	istringstream iss("(Bosse,Bil Doktorn,1921)");
	cout << s1 << endl;
	cout << s2 << endl;
	iss >> s1;
	cout << s1 << endl;
}

void main3_4()
{
	cout << "main4_1" << endl;
	Student s1("Kalle", "Anka", 1991);
	Student s2,s3;
	s2.setFirstName("Anders");
	s2.setSecondName("And");
	s2.setEnrollmentYear(1992);
	istringstream iss("(Bosse,Bil Doktorn,1921)");
	iss >> s3;
	
	StudentRegister sr;
	sr.add(s1);
	sr.add(s2);
	sr.add(s3);
	cout << sr.list();
}

void main3_5()
{
	cout << "main3_4" << endl;
	Student s1("Kalle", "Anka", 1991);
	Student s2("Anders","And",1992);
	Student s3("Bosse","Bil Doktorn",1921);
	StudentRegister sr;
	sr.add(s1);
	sr.add(s2);
	sr.add(s3);
	sr.WriteToFile("test.txt");
}

void main3_6()
{
	cout << "main3_5" << endl;
	Student s1("Kalle", "Anka", 1991);
	Student s2("Anders", "And", 1992);
	Student s3("Bosse", "Bil Doktorn", 1921);
	StudentRegister sr;
	sr.add(s1);
	sr.add(s2);
	sr.add(s3);
	sr.WriteToFile("test.txt");
	StudentRegister sr2;
	sr2.ReadFromFile("db.txt");
	sr2.WriteToFile("test2.txt");
	cout << sr2.list() << endl;
}

void main4_1()
{
	cout << "main4_1" << endl;
	StudentRegister sr;
	sr.menu();
}

void main5_1()
{
	cout << "main5_1" << endl;
	Course c("Course", 1990);
	LanguageCourse lc("LanguageCourse", 1991, 'B', 'C');
	Mathematics m("Mathematics", 1992, 'A');
	English e("English", 1993, 'C', 'F');
	Swedish s("Swedish", 1994, 'A', 'B', true);
	vector<Course*> v;
	v.push_back(&c);
	v.push_back(&lc);
	v.push_back(&m);
	v.push_back(&e);
	v.push_back(&s);
	for (auto item : v)
	{
		item->print();
		cout << endl;
	}
}

void main5_2()
{
	cout << "main5_2" << endl;
	try
	{
		Mathematics m1("Mathematics", 1992, 'A');
		Mathematics m2("Mathematics", 1992, 'X');
	}
	catch (CourseException e)
	{
		cout << "Exception thrown: " << endl;
		cout << e.getMessage();
	}
}

int main()
{
	//main3_1();
	//main3_2();
	//main3_3();
	//main3_4();
	//main3_5();
	//main3_6();
	//main4_1();
	//main5_1();
	main5_2();
	system("pause");
	return 0;
}